import { DataSource } from 'typeorm';
import { User } from '../modules/user/entities/user.entity';
import { Activity } from '../modules/activity/entities/activity.entity';
import { ActivityFavorite } from '../modules/activity/entities/activity-favorite.entity';
import { Comment } from '../modules/comment/entities/comment.entity';
import { SmsCode } from '../modules/sms/entities/sms-code.entity';
import { OperationLog } from '../modules/operation-log/entities/operation-log.entity';
import { UserMessageMapping } from '../modules/message/entities/user-message-mapping.entity';
import { CreateActivityFavorites1682513064000 } from '../migrations/1682513064000-CreateActivityFavorites';
import { AddMissingUserFields1625000000001 } from '../migrations/1625000000001-AddMissingUserFields';
import { FixUniqueConstraints1625000000002 } from '../migrations/1625000000002-FixUniqueConstraints';
import { FixEmptyPasswords1625000000003 } from '../migrations/1625000000003-FixEmptyPasswords';

export const AppDataSource = new DataSource({
  type: 'mysql',
  host: process.env.DB_HOST || 'localhost',
  port: process.env.DB_PORT ? parseInt(process.env.DB_PORT, 10) : 3306,
  username: process.env.DB_USERNAME || 'root',
  password: process.env.DB_PASSWORD || '123456',
  database: process.env.DB_DATABASE || 'hdq-news',
  entities: [
    User,
    Activity,
    ActivityFavorite,
    Comment,
    SmsCode,
    OperationLog,
    UserMessageMapping
  ],
  migrations: [
    CreateActivityFavorites1682513064000,
    AddMissingUserFields1625000000001,
    FixUniqueConstraints1625000000002,
    FixEmptyPasswords1625000000003,
   
  ],
  synchronize: false,
  logging: true,
  extra: {
    timezone: '+08:00'
  }
});
